package com.huangpeng.designmodel.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author huangpeng
 * @Title 学科类
 * @Package
 * @Date 2020/10/26 10:18
 * @Description 学科类
 * @Version 1.0
 */
public class Message {
    private List<Observer> observers = new ArrayList<>();
    private String msg;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
        notifyAllObservers();
    }

    public void attach(Observer observer){
        observers.add(observer);
    }

    public void notifyAllObservers() {
        for(Observer observer : observers){
            observer.update();
        }
    }
}
